package com.yspa.util;

import net.sf.json.JSONObject;

import com.baidu.yun.core.log.YunLogEvent;
import com.baidu.yun.core.log.YunLogHandler;
import com.baidu.yun.push.auth.PushKeyPair;
import com.baidu.yun.push.client.BaiduPushClient;
import com.baidu.yun.push.constants.BaiduPushConstants;
import com.baidu.yun.push.exception.PushClientException;
import com.baidu.yun.push.exception.PushServerException;
import com.baidu.yun.push.model.PushMsgToAllRequest;
import com.baidu.yun.push.model.PushMsgToAllResponse;

public class AndroidPushMsgToAll {
	public static void main(String[] args) throws PushClientException,
			PushServerException {

		// 创建 Android的通知
		JSONObject notification = new JSONObject();
		notification.put("title", "TEST");
		notification.put("description", "Hello Baidu Push");
		notification.put("notification_builder_id", 0);
		notification.put("notification_basic_style", 4);
		notification.put("open_type", 1);
		// notification.put("url", "http://push.baidu.com");
		JSONObject jsonCustormCont = new JSONObject();
		jsonCustormCont.put("key", "value"); // 自定义内容，key-value
		notification.put("custom_content", jsonCustormCont);

		// 4. specify request arguments
		PushMsgToAllRequest request = new PushMsgToAllRequest()
				.addMsgExpires(new Integer(3600)).addMessageType(1)
				.addMessage(notification.toString()) // 添加透传消息
				.addSendTime(System.currentTimeMillis() / 1000 + 70) // 设置定时推送时间，必需超过当前时间一分钟，单位秒.实例2分钟后推送
				.addDeviceType(3);

		PushMsg.pushMsgToAll(request);
	}
}
